<?php
function getOnSale($category)
{
	$goSignal = ($category == 'men' || $category == 'women' || $category == 'accessories' ? true : false);
	
	$imgFolder = './img/categories/'.$category.'/';
	
	if($goSignal)
	{
		$tableSearched = ($category == 'men' ? 'ex_gallery_m' : ($category == 'accessories' ? 'ex_gallery_a' : ($category == 'women' ? 'ex_gallery_w' : '')));
		
		$tables = array();
		$tables[0] = $tableSearched;
		
		$fields = array();
		$fields[0] = 'itemID';
		$fields[1] = 'itemName';
		$fields[2] = 'itemImg1';
		$fields[3] = 'itemPrice';
		$fields[4] = 'itemSubCat';
		$fields[5] = 'active';
		if($category == 'men' || $category == 'women')
		{
			$fields[6] = 'size6';
			$fields[7] = 'size65';
			$fields[8] = 'size7';
			$fields[9] = 'size8';
			$fields[10] = 'size9';
			$fields[11] = 'size10';
		}
		if($category == 'men')
		{
			$fields[12] = 'size85';
			$fields[13] = 'size95';
			$fields[14] = 'size11';
		}
		else if($category == 'women')
		{
			$fields[12] = 'size85';
		}
		
		$whereClause = 'active > 1';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		$returnVar = '';
		if($data['queryStatus'] == "DB Query success!")
		{
			for ($i=0; $i<sizeOf($data['itemID']); $i++)
			{
				$sizesClassNames = '';
		
				for ($x=6; $x<sizeOf($fields); $x++)
				{
					if($data[$fields[$x]][$i] == '1')
					{
						$sizesClassNames .= str_ireplace('ize', '', $fields[$x]).' ';
					}
				}
				$returnVar .= '
				<div class="'.$sizesClassNames.'itemLink">
					'.($data['active'][$i] > 1 ? '<div class="sale"></div>' : '').'
					<img src="'.$imgFolder.$data['itemSubCat'][$i].'/'.$data['itemImg1'][$i].'" class="thumb" alt="'.$data['itemID'][$i].'"/><br />
					<a href="'.INDEX.'product'.EXT.'category='.$category.'&sub='.$data['itemSubCat'][$i].'&id='.$data['itemID'][$i].'" id="item'.$data['itemID'][$i].'">'.$data['itemName'][$i].'</a><br />
					<span class="price">'.($data['active'][$i] > 1 ? '<del>PHP '.number_format($data['itemPrice'][$i], 2, '.', ',').'</del> PHP '.number_format($data['itemPrice'][$i] * ((100-$data['active'][$i])/100), 2, '.', ',') : 'PHP '.number_format($data['itemPrice'][$i], 2, '.', ',')).'</span>
				</div>
				';
			}
		}
		else
		{
			$returnVar = '<br /><br />There are no products on sale for this category.<br /><br />';
		}
		return $returnVar;
	}
	else
	{
	}	

}

function displaySearch($category, $searchString)
{
	$goSignal = ($category == 'men' || $category == 'women' || $category == 'accessories' || $category == 'search' ? true : false);
	
	$imgFolder = './img/categories/'.$category.'/';
	
	if($goSignal)
	{
		$tableSearched = ($category == 'men' ? 'ex_gallery_m' : ($category == 'accessories' ? 'ex_gallery_a' : ($category == 'women' ? 'ex_gallery_w' : '')));
		
		$tables = array();
		$tables[0] = $tableSearched;
		
		$fields = array();
		$fields[0] = 'itemID';
		$fields[1] = 'itemName';
		$fields[2] = 'itemImg1';
		$fields[3] = 'itemPrice';
		$fields[4] = 'itemSubCat';
		$fields[5] = 'active';
		if($category == 'men' || $category == 'women')
		{
			$fields[6] = 'size6';
			$fields[7] = 'size65';
			$fields[8] = 'size7';
			$fields[9] = 'size8';
			$fields[10] = 'size9';
			$fields[11] = 'size10';
		}
		if($category == 'men')
		{
			$fields[12] = 'size85';
			$fields[13] = 'size95';
			$fields[14] = 'size11';
		}
		else if($category == 'women')
		{
			$fields[12] = 'size85';
		}
		
		
		
		$subWhere = '(itemSubCat LIKE "%'.matchSubNavHref($searchString).'%" OR itemName LIKE "%'.$searchString.'%" OR itemDesc LIKE "%'.$searchString.'%") AND ';
		
		$whereClause = $subWhere.'active > 0';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		$returnVar = '';
		if($data['queryStatus'] == "DB Query success!")
		{
			for ($i=0; $i<sizeOf($data['itemID']); $i++)
			{
				$sizesClassNames = '';
		
				for ($x=6; $x<sizeOf($fields); $x++)
				{
					if($data[$fields[$x]][$i] == '1')
					{
						$sizesClassNames .= str_ireplace('ize', '', $fields[$x]).' ';
					}
				}
				$returnVar .= '
				<div class="'.$sizesClassNames.'itemLink">
					'.($data['active'][$i] > 1 ? '<div class="sale"></div>' : '').'
					<img src="'.$imgFolder.$data['itemSubCat'][$i].'/'.$data['itemImg1'][$i].'" class="thumb" alt="'.$data['itemID'][$i].'"/><br />
					<a href="'.INDEX.'product'.EXT.'category='.$category.'&sub='.$data['itemSubCat'][$i].'&id='.$data['itemID'][$i].'" id="item'.$data['itemID'][$i].'">'.$data['itemName'][$i].'</a><br />
					<span class="price">'.($data['active'][$i] > 1 ? '<del>PHP '.number_format($data['itemPrice'][$i], 2, '.', ',').'</del> PHP '.number_format($data['itemPrice'][$i] * ((100-$data['active'][$i])/100), 2, '.', ',') : 'PHP '.number_format($data['itemPrice'][$i], 2, '.', ',')).'</span>
				</div>
				';
			}
		}
		else
		{
			$returnVar = '<br /><br />There are no products that match your search for this category.<br /><br />';
		}
		return $returnVar;
	}
	else
	{
	}	
}

function displayThumbnailGallery($category, $subcategory, $imgFolder)
{
	$goSignal = ($category == 'men' || $category == 'women' || $category == 'accessories' ? true : false);
	
	if($goSignal)
	{
		$tableSearched = ($category == 'men' ? 'ex_gallery_m' : ($category == 'accessories' ? 'ex_gallery_a' : ($category == 'women' ? 'ex_gallery_w' : '')));
		
		$tables = array();
		$tables[0] = $tableSearched;
		
		$fields = array();
		$fields[0] = 'itemID';
		$fields[1] = 'itemName';
		$fields[2] = 'itemImg1';
		$fields[3] = 'itemPrice';
		$fields[4] = 'itemSubCat';
		$fields[5] = 'active';
		if($category == 'men' || $category == 'women')
		{
			$fields[6] = 'size6';
			$fields[7] = 'size65';
			$fields[8] = 'size7';
			$fields[9] = 'size8';
			$fields[10] = 'size9';
			$fields[11] = 'size10';
		}
		if($category == 'men')
		{
			$fields[12] = 'size85';
			$fields[13] = 'size95';
			$fields[14] = 'size11';
		}
		else if($category == 'women')
		{
			$fields[12] = 'size85';
		}
		
		$subWhere = ($subcategory == 'all' ? '' : 'itemSubCat = "'.$subcategory.'" AND ');
		
		$whereClause = $subWhere.'active > 0';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		
		
		
		$returnVar = '';
		if($data['queryStatus'] == "DB Query success!")
		{
			for ($i=0; $i<sizeOf($data['itemID']); $i++)
			{
				$sizesClassNames = '';
		
				for ($x=6; $x<sizeOf($fields); $x++)
				{
					if($data[$fields[$x]][$i] == '1')
					{
						$sizesClassNames .= str_ireplace('ize', '', $fields[$x]).' ';
					}
				}
				$returnVar .= '
				<div class="'.$sizesClassNames.'itemLink">
					'.($data['active'][$i] > 1 ? '<div class="sale"></div>' : '').'
					<img src="'.$imgFolder.$data['itemSubCat'][$i].'/'.$data['itemImg1'][$i].'" class="thumb" alt="'.$data['itemID'][$i].'"/><br />
					<a href="'.INDEX.'product'.EXT.'category='.$category.'&sub='.$data['itemSubCat'][$i].'&id='.$data['itemID'][$i].'" id="item'.$data['itemID'][$i].'">'.$data['itemName'][$i].'</a><br />
					<span class="price">'.($data['active'][$i] > 1 ? '<del>PHP '.number_format($data['itemPrice'][$i], 2, '.', ',').'</del> PHP '.number_format($data['itemPrice'][$i] * ((100-$data['active'][$i])/100), 2, '.', ',') : 'PHP '.number_format($data['itemPrice'][$i], 2, '.', ',')).'</span>
				</div>
				';
			}
		}
		else
		{
			$returnVar = '<br /><br /><br /><br />You have no products for this category.';
		}
		return $returnVar;
	}
	else
	{
	}	
}
?>